package com.songlanyun.modules.ad.controller.api;


import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.ad.entity.AdEntity;
import com.songlanyun.modules.ad.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 广告表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-11 13:55:19
 */
@RestController
@RequestMapping("api/ad/ad")
public class AdApiController extends AbstractApiController {
    @Autowired
    private AdService adService;

    /**
     * 根据商铺id查询商铺广告
     */
    @GetMapping("/getShopAd/{shopId}")
//    @RequiresPermissions("ad:ad:list")
    public R getShopAd(@PathVariable("shopId") Long shopId, @RequestParam Map<String, Object> params) {

        //查询当前商家的广告
        List<AdEntity> list = adService.getShopAd(params, shopId);

        return R.ok().put("list", list);
    }

    /**
     * 根据商铺id和广告位标识码查询对应的广告
     */


    @GetMapping("/getShopAdByAdL/{shopId}/{markCode}")
//    @RequiresPermissions("ad:ad:list")
    public R getShopAdByAdL(@PathVariable("shopId") Long shopId, @PathVariable("markCode") String markCode) {

        System.out.println("广告接口调用");
        //查询当前商家的广告
        List<AdEntity> list = adService.getShopAdByAdL(shopId, markCode);

        return R.ok().put("list", list);
    }


    /**
     * 根据广告查询对应广告和广告位信息
     */
    @GetMapping("/info/{id}")
//    @RequiresPermissions("ad:ad:info")
    public R info(@PathVariable("id") Integer id) {
        AdEntity ad = adService.getInfo(id);

        return R.ok().put("data", ad);
    }

    /**
     * 根据广告位标识码查询对应的广告
     */
    @GetMapping("/getByCode/{markCode}")
//    @RequiresPermissions("ad:ad:list")
    public R getShopAdByAdL(@PathVariable("markCode") String markCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("markCode", markCode);
        //查询当前商家的广告
        List<AdEntity> list = adService.adList(map);

        return R.ok().put("list", list);
    }

}
